package com.daka.controller;

import com.daka.bean.User;
import com.daka.service.UserService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

@RestController
@RequestMapping(value = "/")
public class UserController {

    @Autowired
    UserService userService;

    @GetMapping("/index")
    public String index() {
        return "welcome";
    }

    @PostMapping("/request")
    /**
     * 日期是每天在
     */
    public ResponseEntity insert(@RequestBody User record) throws ParseException {
        return  userService.insert(record);
    }

    /**
     * @return
     */
    @GetMapping("/findAll")
    public ResponseEntity findAll() throws ParseException {
        return userService.findAll();
    }

    /**
     * @return
     */
    @GetMapping("/findAll1")
    public ResponseEntity findAll1() throws ParseException {
        return userService.findAll1();
    }

    /**
     * @return
     */
    @GetMapping("/findMe")
    public ResponseEntity findAll(@RequestBody User user) throws ParseException {
        return userService.findMe(user);
    }

    /**
     * delete
     */
    @DeleteMapping("delete")
    public ResponseEntity delete(@RequestBody User user) throws ParseException {
        return userService.delete(user);
    }


    /**
     * delete
     */
    @PostMapping("backup")
    public ResponseEntity backup() throws ParseException {
        return userService.backup();
    }
}
